package com.bjtu.laorenyouhao.guanliyuan.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bjtu.common.valid.group.AddGroupp;
import com.bjtu.common.valid.group.UpdateGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bjtu.laorenyouhao.guanliyuan.entity.RoomEntity;
import com.bjtu.laorenyouhao.guanliyuan.service.RoomService;
import com.bjtu.common.utils.PageUtils;
import com.bjtu.common.utils.R;



/**
 * 地点表
 *
 * @author yangyalong
 * @email yangyalong@gmail.com
 * @date 2021-07-08 21:01:02
 */
@RestController
@RequestMapping("guanliyuan/room")
public class RoomController {
    @Autowired
    private RoomService roomService;


    @RequestMapping("/getId")
    public R getRoomeId(@RequestParam String name){
        RoomEntity room = roomService.getOne(new QueryWrapper<RoomEntity>().eq("name", name));
        return R.ok().put("roomId",room.getId());
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = roomService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		RoomEntity room = roomService.getById(id);

        return R.ok().put("room", room);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@Validated(AddGroupp.class) @RequestBody RoomEntity room){
		roomService.save(room);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@Validated(UpdateGroup.class) @RequestBody RoomEntity room){
		roomService.updateById(room);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		roomService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
